/**
 * Ref:
 * when add new DataSet, you need ~~
 * 1) add public static const XXXX:String = "xxxxx";
 * 2) update this.isSelf::Switch , you need to tell what Class it should take.
 * 
 */
package com.cf.core.model.diagram.data {
	import com.cf.core.Utils.debug;
	import com.cf.core.Utils.tools;
	import com.cf.core.model.diagram.constants.BackgroundSet;
	public class DataSet{
		public static const DEFAULT:String =	"DefaultData";
		public static const GRID:String =		"GridData";
		
		
		// Return current class, by checking "this.type"
		public function get currentClass():Class{
			var instance:Class;
			switch(this.type) {
				default: return Error; break;	// user Error to id when fail to check
				case DEFAULT: case GRID:
					instance = DataCheckGrid as Class;
				break;
			}//case
			return instance;
		}//fn
		// param.DataType -> DataSet.type
		private var G_type:String=null;
		public function get type():String { return G_type }
		public function set type(_s:String):void {
			switch(_s) {
				default:
					_s = null;
					debug.msg("DataSet : [" + _s + "] not an available type.");
				break;
				case DEFAULT:
				case GRID:
					G_type = _s;
				break;
			}//case
		}//setter
		
		/**
		 * You should add data, chart, point, by this function.
		 * it will auto check the data format, and init the default value by DataCheckBase.as & it's child
		 */
		public function add(_input:Object):void {
			var _flag:Boolean = true;
			var _formatList:Array = new Array();
			var _inputList:Array = new Array();
			if(this.currentClass!=Error){	// please setup by this.type=DataSet.DEFAULT/GRID/....
				var _tmpClass:Class = currentClass as Class;
				var _instance:Object = new _tmpClass;
			}else {
				debug.msg("DataSet.add : init the currentClass FAIL.");
				return;
			}//if
			for (var _notes in _input) {
				// OK. added value form _input to new Array Child
				if ( isSelf(_notes) ) {
					// input value found on request format.
					if (typeof(_instance[_notes]) == typeof(_input[_notes])) {
						// ALL PASS, no problem.
						_instance[_notes] = _input[_notes];
						_formatList.push("\t" + _notes +"\t="+_input[_notes]+"\t [Pass]");
					}else {
						// the value type is not equal.
						_flag = false;
						_formatList.push("\t" + _notes +"\t=" + _input[_notes] + "\t [value type should be:"+ typeof(_instance[_notes]) +"]");
					}//try
				}else {
					// input value not found on request format.
					_formatList.push("\t" + _notes +"\t="+_input[_notes]+"\t [Not exist] <<<<<<<<<<< ");
					_flag = false;
				}//if
			}//for
			if ( _flag ) {
				// All info pass the checking
				G_ram.push(_instance);
			}else {
				// some checking not pass.
				debug.msg("DataSet.add : input data format checking : " + ((_flag)?"pass":"not pass."));
				debug.msg("Fail Dataset :\n" + _formatList.join("\n"));
			}//if
		}//fn
		
		/*****  MISC *****
		 *
		 * 
		 * 
		 * Check if input param's name is current type's property return true.
		 * @param	_current_param
		 * @return
		 */
		public function isSelf(_current_param:String):Boolean {
			var _flag:Boolean = false;
			var _grid:DataCheckGrid = new DataCheckGrid();
			// first checking. current type is setted;
			if (this.type == null) return false;
			switch(this.type) {
				default: return false; break;
				case GRID:
					if (_current_param in _grid) _flag = true; else _flag = false;
				break;
			}//case
			return _flag;
		}//fn
		
		private var G_ram:Array;
		public function get ram():Array{return G_ram}
		public function get length():uint { return G_ram.length }
		
		public function DataSet():void { RELEASE(); }
		public function RELEASE(e:*=null):void {
			// how to clear up.
			G_ram=new Array();
		}//fn
	}//class
}//package